﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.huawei.esdk.tp.professional.eSDKTPProfessionalConfMgr;
using com.huawei.esdk.tp.professional.DataType;
using System.Web.Services.Protocols;
using System.Collections;
using com.huawei.esdk.tp.professional.Utils;
using System.Security.Cryptography;

namespace com.huawei.esdk.tp.professional.local
{
    public partial class ConferenceMgrServiceEx
    {
        private static string url = com.huawei.esdk.tp.professional.Utils.UtilsSettings.URL + com.huawei.esdk.tp.professional.Utils.UtilsSettings.tpProfessionalConfMgr;
        private static TPProfessionalConfMgrService confMgr = new TPProfessionalConfMgrService(url);

        EncryptUtiles encryptUtiles = new EncryptUtiles();

        private static ConferenceMgrServiceEx instance = null;
        protected ConferenceMgrServiceEx()
        {

        }
        public static ConferenceMgrServiceEx Instance()
        {
            if (null == instance)
            {
                instance = new ConferenceMgrServiceEx();
            }
            return instance;
        }



        public TPSDKResponseEx<ConferenceInfoEx> scheduleConfEx(ConferenceInfoEx scheduleConf)
        {
            TPSDKResponseEx<ConferenceInfoEx> resp = new TPSDKResponseEx<ConferenceInfoEx>();

            try
            {
                confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
                if (null != scheduleConf.auxVideoFormat)
                {
                    scheduleConf.auxVideoFormatSpecified = true;
                }
                if (null != scheduleConf.auxVideoProtocol)
                {
                    scheduleConf.auxVideoProtocolSpecified = true;
                }
                if (null != scheduleConf.isRecording)
                {
                    scheduleConf.isRecordingSpecified = true;
                }
                if (null != scheduleConf.isLiveBroadcast)
                {
                    scheduleConf.isLiveBroadcastSpecified = true;
                }

                foreach (SiteInfoEx siteInfo in scheduleConf.sites)
                {
                    if (siteInfo.videoFormat != null)
                    {
                        siteInfo.videoFormatSpecified = true;
                    }
                    if (siteInfo.videoProtocol != null)
                    {
                        siteInfo.videoProtocolSpecified = true;
                    }
                    if (siteInfo.isLockVideoSource != null)
                    {
                        siteInfo.isLockVideoSourceSpecified = true;
                    }
                    if (siteInfo.participantType != null)
                    {
                        siteInfo.participantTypeSpecified = true;
                    }
                }

                if (scheduleConf.password != null && scheduleConf.password != "")
                {
                    scheduleConf.password = encryptUtiles.EncryptMethod(scheduleConf.password);
                    //scheduleConf.password = rsa2048.AESEncrypt(scheduleConf.password, AuthorizeServiceEx.secretKey, AuthorizeServiceEx.iv);
                    //scheduleConf.password = rsa2048.RSAEncrypt(scheduleConf.password);
                }
                if (scheduleConf.chairmanPassword != null && scheduleConf.chairmanPassword != "")
                {
                    scheduleConf.chairmanPassword = encryptUtiles.EncryptMethod(scheduleConf.chairmanPassword);
                    //scheduleConf.chairmanPassword = rsa2048.AESEncrypt(scheduleConf.chairmanPassword, AuthorizeServiceEx.secretKey, AuthorizeServiceEx.iv);
                    //scheduleConf.chairmanPassword = rsa2048.RSAEncrypt(scheduleConf.chairmanPassword);
                }

                ConferenceInfoEx conferenceInfoEx = new ConferenceInfoEx();
                int resultCode = confMgr.scheduleConfEx(scheduleConf, out conferenceInfoEx);
                if (resultCode == 0)
                {
                    resp.result = 0 == resultCode ? conferenceInfoEx : null;
                }
                resp.resultCode = resultCode;

                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }
        }

        public TPSDKResponseEx<RecurrenceConfInfoEx> scheduleRecurrenceConferenceEx(RecurrenceConfInfoEx scheduleConf)
        {
            TPSDKResponseEx<RecurrenceConfInfoEx> resp = new TPSDKResponseEx<RecurrenceConfInfoEx>();

            try
            {
                confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
                if (null != scheduleConf.auxVideoFormat)
                {
                    scheduleConf.auxVideoFormatSpecified = true;
                }
                if (null != scheduleConf.auxVideoProtocol)
                {
                    scheduleConf.auxVideoProtocolSpecified = true;
                }
                if (null != scheduleConf.isRecording)
                {
                    scheduleConf.isRecordingSpecified = true;
                }
                if (null != scheduleConf.isLiveBroadcast)
                {
                    scheduleConf.isLiveBroadcastSpecified = true;
                }

                foreach (SiteInfoEx siteInfo in scheduleConf.sites)
                {
                    if (siteInfo.videoFormat != null)
                    {
                        siteInfo.videoFormatSpecified = true;
                    }
                    if (siteInfo.videoProtocol != null)
                    {
                        siteInfo.videoProtocolSpecified = true;
                    }
                    if (siteInfo.isLockVideoSource != null)
                    {
                        siteInfo.isLockVideoSourceSpecified = true;
                    }
                    if (siteInfo.participantType != null)
                    {
                        siteInfo.participantTypeSpecified = true;
                    }
                }

                if (scheduleConf.password != null && scheduleConf.password != "")
                {
                    scheduleConf.password = encryptUtiles.EncryptMethod(scheduleConf.password);
                    //scheduleConf.password = rsa2048.AESEncrypt(scheduleConf.password, AuthorizeServiceEx.secretKey, AuthorizeServiceEx.iv);
                    //scheduleConf.password = rsa2048.RSAEncrypt(scheduleConf.password);
                }
                if (scheduleConf.chairmanPassword != null && scheduleConf.chairmanPassword != "")
                {
                    scheduleConf.chairmanPassword = encryptUtiles.EncryptMethod(scheduleConf.chairmanPassword);
                    //scheduleConf.chairmanPassword = rsa2048.AESEncrypt(scheduleConf.chairmanPassword, AuthorizeServiceEx.secretKey, AuthorizeServiceEx.iv);
                    //scheduleConf.chairmanPassword = rsa2048.RSAEncrypt(scheduleConf.chairmanPassword);
                }

                RecurrenceConfInfoEx conferenceInfoEx;
                int resultCode = confMgr.scheduleRecurrenceConferenceEx(scheduleConf, out conferenceInfoEx);
                if (resultCode == 0)
                {
                    resp.result = 0 == resultCode ? conferenceInfoEx : null;
                }
                resp.resultCode = resultCode;

                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }


        }

        public TPSDKResponseEx<ConferenceInfoEx> editScheduledConfEx(ConferenceInfoEx scheduleConf)
        {
            TPSDKResponseEx<ConferenceInfoEx> resp = new TPSDKResponseEx<ConferenceInfoEx>();

            try
            {
                confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
                if (null != scheduleConf.auxVideoFormat)
                {
                    scheduleConf.auxVideoFormatSpecified = true;
                }
                if (null != scheduleConf.auxVideoProtocol)
                {
                    scheduleConf.auxVideoProtocolSpecified = true;
                }
                if (null != scheduleConf.isRecording)
                {
                    scheduleConf.isRecordingSpecified = true;
                }
                if (null != scheduleConf.isLiveBroadcast)
                {
                    scheduleConf.isLiveBroadcastSpecified = true;
                }

                foreach (SiteInfoEx siteInfo in scheduleConf.sites)
                {
                    if (siteInfo.videoFormat != null)
                    {
                        siteInfo.videoFormatSpecified = true;
                    }
                    if (siteInfo.videoProtocol != null)
                    {
                        siteInfo.videoProtocolSpecified = true;
                    }
                    if (siteInfo.isLockVideoSource != null)
                    {
                        siteInfo.isLockVideoSourceSpecified = true;
                    }
                    if (siteInfo.participantType != null)
                    {
                        siteInfo.participantTypeSpecified = true;
                    }
                }

                if (scheduleConf.password != null && scheduleConf.password != "")
                {
                    scheduleConf.password = encryptUtiles.EncryptMethod(scheduleConf.password);
                    //scheduleConf.password = rsa2048.AESEncrypt(scheduleConf.password, AuthorizeServiceEx.secretKey, AuthorizeServiceEx.iv);
                    //scheduleConf.password = rsa2048.RSAEncrypt(scheduleConf.password);
                }
                if (scheduleConf.chairmanPassword != null && scheduleConf.chairmanPassword != "")
                {
                    scheduleConf.chairmanPassword = encryptUtiles.EncryptMethod(scheduleConf.chairmanPassword);
                    //scheduleConf.chairmanPassword = rsa2048.AESEncrypt(scheduleConf.chairmanPassword, AuthorizeServiceEx.secretKey, AuthorizeServiceEx.iv);
                    //scheduleConf.chairmanPassword = rsa2048.RSAEncrypt(scheduleConf.chairmanPassword);
                }

                ConferenceInfoEx conferenceInfoEx;
                int resultCode = confMgr.editScheduledConfEx(scheduleConf, out conferenceInfoEx);
                if (resultCode == 0)
                    resp.result = 0 == resultCode ? conferenceInfoEx : null;
                resp.resultCode = resultCode;

                return resp;

            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }

        }

        public TPSDKResponseEx<RecurrenceConfInfoEx> editRecurrenceConferenceEx(RecurrenceConfInfoEx scheduleConf, System.Nullable<System.DateTime> beginTime)
        {
            TPSDKResponseEx<RecurrenceConfInfoEx> resp = new TPSDKResponseEx<RecurrenceConfInfoEx>();

            try
            {
                confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
                if (null != scheduleConf.auxVideoFormat)
                {
                    scheduleConf.auxVideoFormatSpecified = true;
                }
                if (null != scheduleConf.auxVideoProtocol)
                {
                    scheduleConf.auxVideoProtocolSpecified = true;
                }
                if (null != scheduleConf.isRecording)
                {
                    scheduleConf.isRecordingSpecified = true;
                }
                if (null != scheduleConf.isLiveBroadcast)
                {
                    scheduleConf.isLiveBroadcastSpecified = true;
                }

                foreach (SiteInfoEx siteInfo in scheduleConf.sites)
                {
                    if (siteInfo.videoFormat != null)
                    {
                        siteInfo.videoFormatSpecified = true;
                    }
                    if (siteInfo.videoProtocol != null)
                    {
                        siteInfo.videoProtocolSpecified = true;
                    }
                    if (siteInfo.isLockVideoSource != null)
                    {
                        siteInfo.isLockVideoSourceSpecified = true;
                    }
                    if (siteInfo.participantType != null)
                    {
                        siteInfo.participantTypeSpecified = true;
                    }
                }

                if (scheduleConf.password != null && scheduleConf.password != "")
                {
                    scheduleConf.password = encryptUtiles.EncryptMethod(scheduleConf.password);
                    //scheduleConf.password = rsa2048.AESEncrypt(scheduleConf.password, AuthorizeServiceEx.secretKey, AuthorizeServiceEx.iv);
                    //scheduleConf.password = rsa2048.RSAEncrypt(scheduleConf.password);
                }
                if (scheduleConf.chairmanPassword != null && scheduleConf.chairmanPassword != "")
                {
                    scheduleConf.chairmanPassword = encryptUtiles.EncryptMethod(scheduleConf.chairmanPassword);
                    //scheduleConf.chairmanPassword = rsa2048.AESEncrypt(scheduleConf.chairmanPassword, AuthorizeServiceEx.secretKey, AuthorizeServiceEx.iv);
                    //scheduleConf.chairmanPassword = rsa2048.RSAEncrypt(scheduleConf.chairmanPassword);
                }

                RecurrenceConfInfoEx conferenceInfoEx;

                bool beginTimeSpecified = false;
                if (null != beginTime)
                {
                    beginTimeSpecified = true;
                }

                int resultCode = confMgr.editRecurrenceConferenceEx(scheduleConf, beginTime, beginTimeSpecified, out conferenceInfoEx);
                if (resultCode == 0)
                {
                    resp.result = 0 == resultCode ? conferenceInfoEx : null;
                }

                resp.resultCode = resultCode;

                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }

        }

        public TPSDKResponseEx<List<SiteInfoEx>> querySitesEx()
        {
            TPSDKResponseEx<List<SiteInfoEx>> resp = new TPSDKResponseEx<List<SiteInfoEx>>();
            try
            {
                confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;

                int resultCode;
                SiteInfoEx[] siteInfoExs;

                resultCode = confMgr.querySitesEx(out siteInfoExs);
                if (0 == resultCode)
                {
                    List<SiteInfoEx> list = new List<SiteInfoEx>();
                    foreach (SiteInfoEx siteInfoEx in siteInfoExs)
                    {
                        list.Add(siteInfoEx);
                    }
                    resp.result = list;
                }
                else
                {
                    resp.result = null;
                }
                resp.resultCode = resultCode;
                return resp;

            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }

        }

        public int prolongScheduledConfEx(string confId, System.Nullable<System.DateTime> beginDate, string prolongTime)
        {
            try
            {
                confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode;
                bool beginDateSpecified = false;
                if (null != beginDate)
                {
                    beginDateSpecified = true;
                }

                resultCode = confMgr.prolongScheduledConfEx(confId, beginDate, beginDateSpecified, prolongTime);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public TPSDKResponseEx<Dictionary<string, List<FreeBusyStateEx>>> querySiteStatusEx(List<string> siteUris, System.DateTime beginTime, string duration)
        {
            TPSDKResponseEx<Dictionary<string, List<FreeBusyStateEx>>> resp = new TPSDKResponseEx<Dictionary<string, List<FreeBusyStateEx>>>();
            try
            {
                confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;

                int resultCode;
                SiteFreeBusyStatesEx[] siteFreeBusyStatesExs;
                string[] sites = null;
                if (null != siteUris)
                {
                    sites = siteUris.ToArray<string>();
                }



                resultCode = confMgr.querySiteStatusEx(sites, beginTime, duration, out siteFreeBusyStatesExs);
                if (0 == resultCode)
                {
                    Dictionary<string, List<FreeBusyStateEx>> dictionary = new Dictionary<string, List<FreeBusyStateEx>>();
                    foreach (SiteFreeBusyStatesEx site in siteFreeBusyStatesExs)
                    {
                        List<FreeBusyStateEx> list = new List<FreeBusyStateEx>();
                        foreach (FreeBusyStateEx fbState in site.states)
                        {
                            list.Add(fbState);
                        }
                        dictionary.Add(site.uri, list);
                    }
                    resp.result = dictionary;
                }
                resp.resultCode = resultCode;
                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }


        }

        public TPSDKResponseEx<List<ConferenceStatusEx>> queryConferencesStatusEx(List<string> confIds)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<List<ConferenceStatusEx>> resp = new TPSDKResponseEx<List<ConferenceStatusEx>>();
            try
            {

                int resultCode;
                ConferenceStatusEx[] conferenceStatusExs;
                string[] conferenceIds = null;
                if (null != confIds)
                {
                    conferenceIds = confIds.ToArray<string>();
                }


                resultCode = confMgr.queryConferencesStatusEx(conferenceIds, out conferenceStatusExs);
                if (0 == resultCode)
                {
                    List<ConferenceStatusEx> list = new List<ConferenceStatusEx>();
                    foreach (ConferenceStatusEx confStatusEx in conferenceStatusExs)
                    {
                        list.Add(confStatusEx);
                    }
                    resp.result = list;
                }
                else
                {
                    resp.result = null;
                }
                resp.resultCode = resultCode;
                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }


        }

        public TPSDKResponseEx<List<SiteStatusEx>> queryConfSitesStatusEx(string confId, List<string> siteUris)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<List<SiteStatusEx>> resp = new TPSDKResponseEx<List<SiteStatusEx>>();
            try
            {
                int resultCode;
                SiteStatusEx[] siteStatusExs;
                string[] sites = null;
                if (null != siteUris)
                {
                    sites = siteUris.ToArray<string>();
                }


                resultCode = confMgr.queryConfSitesStatusEx(confId, sites, out siteStatusExs);
                if (0 == resultCode)
                {
                    List<SiteStatusEx> list = new List<SiteStatusEx>();
                    foreach (SiteStatusEx siteStatusEx in siteStatusExs)
                    {
                        list.Add(siteStatusEx);
                    }
                    resp.result = list;
                }
                else
                {
                    resp.result = null;
                }
                resp.resultCode = resultCode;
                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }
        }

        //根据查询条件，查询所有会场列表
        //public TPSDKResponseEx<QuerySitesByConditionExResponse> querySitesByConditionEx( QueryConfigEx queryConfig)
        //{
        //    confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
        //    TPSDKResponseEx<QuerySitesByConditionExResponse> result = new TPSDKResponseEx<QuerySitesByConditionExResponse>();
        //    try
        //    {
        //        QuerySitesByConditionExResponse querySites = new QuerySitesByConditionExResponse();
        //        List<SiteInfoEx> siteInfoList = new List<SiteInfoEx>();
        //        SiteInfoEx[] siteInfos = null;
        //        PageInfoEx pageInfo = new PageInfoEx();

        //        if (queryConfig.pageParam == null)
        //        {
        //            PageParamEx pageParam = new PageParamEx();
        //            pageParam.currentPage = 1;
        //            pageParam.numberPerPage = 15;
        //            queryConfig.pageParam = pageParam;
        //        }

        //        result.resultCode = confMgr.querySitesByConditionEx(queryConfig, out siteInfos, out pageInfo);
        //        if (result.resultCode == 0)
        //        {
        //            for (int i = 0; i < siteInfos.Length; i++)
        //            {
        //                siteInfoList.Add(siteInfos[i]);
        //            }
        //            querySites.siteInfos = siteInfoList;
        //            querySites.pageInfo = pageInfo;
        //            result.result = querySites;
        //        }
        //        return result;
        //    }
        //    catch (SoapHeaderException e)
        //    {
        //        int errorCode = ExceptionUtils.processSoapException(e);
        //        result.resultCode = errorCode;
        //        return result;
        //    }
        //}

        public TPSDKResponseEx<Dictionary<string, List<FreeBusyStateEx>>> synchSiteStatusEx(List<string> siteUris, DateTime beginTime, string duration)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<Dictionary<string, List<FreeBusyStateEx>>> resp = new TPSDKResponseEx<Dictionary<string, List<FreeBusyStateEx>>>();
            try
            {
                int resultCode;
                SiteFreeBusyStatesEx[] siteFreeBusyStatesExs;
                string[] sites = null;
                if (null != siteUris)
                {
                    sites = siteUris.ToArray<string>();
                }

                resultCode = confMgr.synchSiteStatusEx(sites, beginTime, duration, out siteFreeBusyStatesExs);
                if (0 == resultCode)
                {
                    Dictionary<string, List<FreeBusyStateEx>> dictionary = new Dictionary<string, List<FreeBusyStateEx>>();
                    foreach (SiteFreeBusyStatesEx site in siteFreeBusyStatesExs)
                    {
                        List<FreeBusyStateEx> list = new List<FreeBusyStateEx>();
                        foreach (FreeBusyStateEx fbState in site.states)
                        {
                            list.Add(fbState);
                        }
                        dictionary.Add(site.uri, list);
                    }
                    resp.result = dictionary;
                }
                resp.resultCode = resultCode;
                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }
        }

        /// <summary>
        /// 向会议中添加会场
        /// </summary>
        /// <param name="name">会场名</param>
        /// <param name="confID">会议ID</param>
        /// <param name="beginTime">会议开始时间</param>
        /// <param name="siteType">会场类型</param>
        /// <param name="siteUri">会场URI</param>
        /// <returns>结果码</returns>
        public TPSDKResponseEx<List<SiteAccessInfoEx>> addSiteToConfEx(string confId, SiteInfoEx siteInfo, System.Nullable<System.DateTime> beginTime)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<List<SiteAccessInfoEx>> resp = new TPSDKResponseEx<List<SiteAccessInfoEx>>();
            try
            {
                int resultCode;

                if (siteInfo.videoFormat != null)
                {
                    siteInfo.videoFormatSpecified = true;
                }
                if (siteInfo.videoProtocol != null)
                {
                    siteInfo.videoProtocolSpecified = true;
                }
                if (siteInfo.isLockVideoSource != null)
                {
                    siteInfo.isLockVideoSourceSpecified = true;
                }
                if (siteInfo.participantType != null)
                {
                    siteInfo.participantTypeSpecified = true;
                }

                SiteAccessInfoEx[] siteAccessInfoExs;

                if (siteInfo != null)
                {
                    if (siteInfo.videoFormat != null)
                        siteInfo.videoFormatSpecified = true;
                    else
                        siteInfo.videoFormatSpecified = false;

                    if (siteInfo.videoProtocol != null)
                        siteInfo.videoProtocolSpecified = true;
                    else
                        siteInfo.videoProtocolSpecified = false;

                    if (siteInfo.isLockVideoSource != null)
                        siteInfo.isLockVideoSourceSpecified = true;
                    else
                        siteInfo.isLockVideoSourceSpecified = false;

                    if (siteInfo.participantType != null)
                        siteInfo.participantTypeSpecified = true;
                    else
                        siteInfo.participantTypeSpecified = false;
                }

                bool beginTimeSpecified = false;
                if (null != beginTime)
                {
                    beginTimeSpecified = true;
                }

                resultCode = confMgr.addSiteToConfEx(confId, siteInfo, beginTime, beginTimeSpecified, out siteAccessInfoExs);
                if (0 == resultCode)
                {
                    List<SiteAccessInfoEx> list = new List<SiteAccessInfoEx>();
                    foreach (SiteAccessInfoEx siteAccessInfoEx in siteAccessInfoExs)
                    {
                        list.Add(siteAccessInfoEx);
                    }
                    resp.result = list;
                }
                else
                {
                    resp.result = null;
                }
                resp.resultCode = resultCode;
                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }
        }

        public int delSiteFromConfEx(string confId, string siteUri, System.Nullable<System.DateTime> beginTime)
        {
            try
            {
                confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode;
                bool beginDateSpecified = false;
                if (null != beginTime)
                {
                    beginDateSpecified = true;
                }
                resultCode = confMgr.delSiteFromConfEx(confId, siteUri, beginTime, beginDateSpecified);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public int connectSitesEx(string confId, List<string> siteUris)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            try
            {
                int resultCode;
                string[] sites = null;
                if (null != siteUris)
                {
                    sites = siteUris.ToArray<string>();
                }

                resultCode = confMgr.connectSitesEx(confId, sites);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public int disconnectSitesEx(string confId, List<string> siteUris)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            try
            {
                int resultCode;
                string[] sites = null;
                if (null != siteUris)
                {
                    sites = siteUris.ToArray<string>();
                }

                resultCode = confMgr.disconnectSitesEx(confId, sites);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public int delScheduledConfEx(string confId, System.Nullable<System.DateTime> beginTime)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            try
            {
                int resultCode;
                bool beginDateSpecified = false;
                if (null != beginTime)
                {
                    beginDateSpecified = true;
                }
                resultCode = confMgr.delScheduledConfEx(confId, beginTime, beginDateSpecified);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public TPSDKResponseSecondEx<AdhocConferenceEx[], PagesInfoEx> queryAdhocConferencesEx(QueryConfigEx queryConfig)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseSecondEx<AdhocConferenceEx[], PagesInfoEx> result = new TPSDKResponseSecondEx<AdhocConferenceEx[], PagesInfoEx>();
            try
            {
                AdhocConferenceEx[] adhocConferences;
                PagesInfoEx pageInfo = null;

                if (queryConfig.focusItem != null)
                {
                    queryConfig.focusItemSpecified = true;
                }

                if (queryConfig.pageParam == null)
                {
                    PageParamEx pageParam = new PageParamEx();
                    pageParam.currentPage = 1;
                    pageParam.numberPerPage = 15;
                    queryConfig.pageParam = pageParam;
                }

                result.resultCode = confMgr.queryAdhocConferencesEx(queryConfig, out adhocConferences, out pageInfo);
                if (result.resultCode == 0)
                {
                    result.result1 = adhocConferences;
                    result.result2 = pageInfo;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }
        }

        public TPSDKResponseEx<AdhocConfFreeBusyStateEx[]> queryAdhocConfFreeBusyEx(string[] confAccessCodes, System.DateTime beginTime, string duration)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<AdhocConfFreeBusyStateEx[]> result = new TPSDKResponseEx<AdhocConfFreeBusyStateEx[]>();
            try
            {
                AdhocConfFreeBusyStateEx[] freebusy;

                result.resultCode = confMgr.queryAdhocConfFreeBusyEx(confAccessCodes, beginTime, duration, out freebusy);
                if (result.resultCode == 0)
                {
                    result.result = freebusy;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }
        }

        public TPSDKResponseEx<AdhocConfFreeBusyStateEx[]> synchAdhocConfFreeBusyEx(string[] confAccessCodes, System.DateTime beginTime, string duration)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<AdhocConfFreeBusyStateEx[]> result = new TPSDKResponseEx<AdhocConfFreeBusyStateEx[]>();
            try
            {
                AdhocConfFreeBusyStateEx[] freebusy;

                result.resultCode = confMgr.synchAdhocConfFreeBusyEx(confAccessCodes, beginTime, duration, out freebusy);
                if (result.resultCode == 0)
                {
                    result.result = freebusy;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }

        }

        // 2015年1月15日 16：00
        public TPSDKResponseEx<SiteMCUEx[]> queryConfSiteMCUEx(string confId, string[] siteUris, System.Nullable<System.DateTime> beginTime)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<SiteMCUEx[]> result = new TPSDKResponseEx<SiteMCUEx[]>();
            try
            {
                SiteMCUEx[] mcus;

                bool beginTimeSpecified = false;
                if (beginTime != null)
                {
                    beginTimeSpecified = true;
                }

                result.resultCode = confMgr.queryConfSiteMCUEx(confId, siteUris, beginTime, beginTimeSpecified, out mcus);
                if (result.resultCode == 0)
                {
                    result.result = mcus;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }
        }

        public TPSDKResponseEx<GetContinuousPresenceInfoResponseEx> getContinuousPresenceInfoEx(string confId)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<GetContinuousPresenceInfoResponseEx> result = new TPSDKResponseEx<GetContinuousPresenceInfoResponseEx>();
            try
            {
                string[] targets;
                int cpResource = 0;
                int[] supportCPModes;

                result.resultCode = confMgr.getContinuousPresenceInfoEx(confId, out targets, out cpResource, out supportCPModes);
                if (result.resultCode == 0)
                {
                    GetContinuousPresenceInfoResponseEx infoResponse = new GetContinuousPresenceInfoResponseEx();



                    infoResponse.cpResource = cpResource;
                    //result.result.targets = new string[targets.Length];
                    infoResponse.targets = targets;
                    //result.result.supportCPModes = new int[supportCPModes.Length];
                    infoResponse.supportCPModes = supportCPModes;

                    result.result = infoResponse;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }
        }

        public TPSDKResponseSecondEx<int, string[]> getContinuousPresenceParamEx(string confId, string target)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseSecondEx<int, string[]> result = new TPSDKResponseSecondEx<int, string[]>();
            try
            {
                int presenceMode;
                string[] subPics;

                result.resultCode = confMgr.getContinuousPresenceParamEx(confId, target, out presenceMode, out subPics);
                if (result.resultCode == 0)
                {
                    result.result1 = presenceMode;
                    result.result2 = subPics;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }
        }

        // 2015年1月22日 

        //查询多点CDR话单
        public TPSDKResponseEx<QueryMultiPointCDRExResponse> queryMultiPointCDREx(MultiPointCDRQueryConfigEx queryConfig)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<QueryMultiPointCDRExResponse> result = new TPSDKResponseEx<QueryMultiPointCDRExResponse>();
            try
            {
                MultiPointCDREx[] cdr;
                PagesInfoEx pageInfo = null;

                result.resultCode = confMgr.queryMultiPointCDREx(queryConfig, out cdr, out pageInfo);
                if (result.resultCode == 0)
                {
                    QueryMultiPointCDRExResponse response = new QueryMultiPointCDRExResponse();
                    response.cdr = cdr;
                    response.pageInfo = pageInfo;

                    result.result = response;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }
        }

        //查询点对点CDR话单
        public TPSDKResponseEx<QueryPointToPointCDRExResponse> queryPointToPointCDREx(PointToPointCDRQueryConfigEx queryConfig)
        {
            confMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<QueryPointToPointCDRExResponse> result = new TPSDKResponseEx<QueryPointToPointCDRExResponse>();
            try
            {
                PointToPointCDREx[] cdr;
                PagesInfoEx pageInfo = null;

                result.resultCode = confMgr.queryPointToPointCDREx(queryConfig, out cdr, out pageInfo);
                if (result.resultCode == 0)
                {
                    QueryPointToPointCDRExResponse response = new QueryPointToPointCDRExResponse();
                    response.cdr = cdr;
                    response.pageInfo = pageInfo;

                    result.result = response;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }
        }

        
    }
}